#include "qcolorpropertyeditor.h"

#include "qcoloreditordialog.h"

#include "../../shared/property/qabstractproperty.h"
#include "../../shared/host/qabstracthost.h"
#include "../undocommand/qpropertychangedundocommand.h"
#include "../../shared/qpropertyfactory.h"

#include <QFontDialog>

QColorPropertyEditor::QColorPropertyEditor(QAbstractProperty *property,QUndoStack* stack, QWidget *parent):
    QButtonCommonEditor(property,stack,parent),
    m_undo_stack(stack)
{
}

void QColorPropertyEditor::btn_clicked()
{
    QColorEditorDialog dlg(m_property->get_value(),this);
    if(m_property->property("color").toBool())
    {
        dlg.set_color_type();
    }
    dlg.exec();

    if(dlg.get_ret()==1)
    {
        QVariant v=dlg.get_value();

        if(!m_property->cmp(v))
        {
            QPropertyChangedUndoCommand *cmd=new QPropertyChangedUndoCommand(
                        m_property->get_host()->get_uuid(),
                        m_property->get_name(),
                        m_property->get_value(),
                        v);
            m_undo_stack->push(cmd);
        }
    }
}

qRegisterPropertyEditor(Color,QColorPropertyEditor)
